package com.checkchan.ethshare.contract;

import org.web3j.abi.datatypes.Type;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;

import java.math.BigInteger;
import java.util.List;

public class contractTest {

    public static void main(String args[]) throws Exception {

//        BigInteger GAS_PRICE = BigInteger.valueOf(20_000_000_000L);
//        BigInteger GAS_LIMIT = BigInteger.valueOf(4_300_000L);
//
//
        Web3j web3j = Web3j.build(new HttpService("HTTP://127.0.0.1:7545"));
//
//        Credentials credentials = Credentials.create("0b60056ce92577506252cddce1b22a4cde6649b0d6805be64b0e1bf97e0d9ebe");
//
//        ShareContract contract = ShareContract.deploy(web3j,credentials,GAS_PRICE,GAS_LIMIT).send();
//
//        System.out.println("合约地址：" + contract.getContractAddress());

        String sourcePassword = "0b60056ce92577506252cddce1b22a4cde6649b0d6805be64b0e1bf97e0d9ebe";
        String constractAddress = "0x6179071c6f8751f8abb7c1946522f2d26bcd7fc3";
        BigInteger GAS_PRICE = BigInteger.valueOf(20_000_000_000L);
        BigInteger GAS_LIMIT = BigInteger.valueOf(4_300_000L);

        Credentials credentials = Credentials.create(sourcePassword);
        ShareContract contract = ShareContract.load(constractAddress,web3j,credentials,GAS_PRICE,GAS_LIMIT);
        List<Type> shareInfo = contract.getShareInfo(0).send();
        System.out.println(shareInfo.get(2).getValue());
    }
}
